from PIL import Image
import toml
import os

class Instrument_img:
    def __init__(self,img_path):
        #打开图片
        self.img = Image.open(img_path)

    def resize_img(self,width,height):
        #修改图片大小
        self.img = self.img.resize((width,height))
    
    def get_blob(self):
        #获取图片的blob
        return self.img.tobytes()

    def show_blob(self,blob):
        #blob转化为图片
        img = Image.frombytes('RGB',(self.img.width,self.img.height),blob)
        # img.show()
        #将图片return出去
        return img
    
    def get_img(self):
        #获取图片
        return self.img

class Instrument_toml:
    #python往toml文件写入东西
    def SetStrogeToml(self,key,value):
        dic = toml.load('config/config.toml')
        dic[key] = value
        with open('config/config.toml','w',encoding='utf-8') as f:
            toml.dump(dic,f)

    #python读取toml文件
    def GetStrogeToml(self,key):
        dic = toml.load('config/config.toml')
        return dic[key]
